package apigateway.stateCount;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

/**
 * Created by 小泽玛丽罗 on 2017/3/12.
 */

@Component
@Aspect
public class StateAspect {
    ThreadLocal<Long> startTime=new ThreadLocal<>();

    @Pointcut("execution(* apigateway.controller.ViewCOntroller.hello(..))")
    public void weblog(){}

    @Before("weblog()")
    public void before(JoinPoint joinPoint){
        startTime.set(System.currentTimeMillis());
    }

    @AfterReturning(returning = "ret",pointcut = "weblog()")
    public void afterReturning(Object ret){
        System.out.println("执行时间"+(System.currentTimeMillis()-startTime.get()));
    }
}
